import TableData from "@/components/public/el-table-pagination"; //主页面列表
import TableLyout from '@/components/commonPublic/tableLyoutDetail.vue'
import tree from "@/components/materialQualityPage/constructionSiteLaboratoryManage/tree"; //左侧机构树
import CustomDialog from "@/components/materialQualityPage/constructionSiteLaboratoryManage/instrumentEquipmentInfo/index.vue";
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import formJs from "./regexDetail.js"; //新增弹框配置

// import {
// } from "@/api/request.js";
import {
    getInstrumentInfoList, //列表页接口
    deleteInstrumentInfo,//删除

} from "@/api/BackStage/materialQualityPage/request.js";

export default {
    name: "instrumentEquipmentInfoText",
    data() {
        return {
            name: "instrumentEquipmentInfoText",
            isLock: false,
            projectId: null,
            projectName: null,
            loading: false,
            btnObj: [], //按钮
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            radio: "待办",
            // 列表
            getList: {
                fCompanyid: "", //左侧选中组织机构id
                keyType:"",
                keyWord: "", //上方查询条件样品名称
                page: 1, //当前页码
                pageSize: 20, //每页显示条数
                typ:""
               
            },
            isShow: false, //是否显示弹框
            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            tableData: [],
            dialogTitle: null,

        };
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        tree,
        elBreadcrumb,
        CustomDialog
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        this.getList.fCompanyid = this.userInfo.companyId
        this.yj_searchForm(this.getList);
        this.btnRole(this.name)
    },
    methods: {
        refreshList() { //刷新列表
            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },

        closeDialog() {
            this.isShow = false;
        },

        handleRow() { },
        btnRole(name) {
            if (this.userInfo.userId != 'System') {
                var btnList = [];
                var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
                if (ModuleList.length > 0) {
                    ModuleList.map((item) => {
                        if (item.fEncode == name) {
                            btnList = item.modulebuttonList;
                        }
                    });
                    btnList.map(item => {
                        item['disabled'] = false
                    })
                    this.btnObj = btnList
                }
            } else {
                this.btnObj = formJs.btnObj
            }
        },
        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },

        // 新增/编辑
        yj_edit(num) {
            if (num == 5) { // 导出
                if (this.dataFid != null) {
                    this.$message.warning("该功能正在卖力开发中"); 
                } else {
                    this.$message.warning("请先选择需要导出的数据");
                }
            }else if (num == 8) { // 打印
                if (this.dataFid != null) {
                    this.$message.warning("该功能正在卖力开发中"); 
                } else {
                    this.$message.warning("请先选择需要打印的数据");
                }
            }else if (num == 9) { // 导入
                this.$message.warning("该功能正在卖力开发中"); 
            }else if (num == 7) { // 查看
                if (this.dataFid != null) {
                    this.statusNum = num;
         
                    this.editText();
                } else {
                    this.$message.warning("请先选择需要查看的数据");
                }
            } else {
                this.statusNum = num
                if (num == 1) { // 新增
                    this.editText();
                } else if (num == 2) {
                    if (this.dataFid != null) {
                     
                        this.editText();
                    } else {
                        this.$message.warning("请先选择需要编辑的数据");
                    }
                } else if (num == 3) {
                    if (this.dataFid != null) {
    
                        this.yj_delete();
                    } else {
                        this.$message.warning("请先选择需要删除的数据");

                    }
                }
        }
        },
        editText() {
            this.isShow = true;
        },
        // 查看
        // 点击查看
        yj_viewForm(row, label) {
            if (label == "设备编号") {
                this.statusNum = 7
                this.currentRow = row;
                this.isShow = true;
            }
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
        // 获取列表数据
        yj_searchForm(data) {
            var obj = {
                fCompanyid: data.fCompanyid, //左侧选中组织机构id
                page: data.page, //当前页码
                pageSize: data.pageSize, //每页显示条数
                keyWord: data.keyWord, //上方查询条件样品名称
                typ:data.typ,
                keyType:data.keyType
            }
            this.loading = true;
            var that = this;
            getInstrumentInfoList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
         // 删除
         yj_delete() {

            this.$confirm("您是否要永久删除此数据?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.loading = true;
                    this.isLock = true
                    deleteInstrumentInfo({
                        fId: this.dataFid,
                    })
                        .then((res) => {
                            if (res.errcode == 0) {
                                this.isLock = false
                                this.loading = false;
                                this.yj_searchForm(this.getList);
                                this.$message.success("删除成功");
                                this.dataFid = null

                            } else {
                                this.isLock = false
                                this.$message.error("删除失败", res.msg);
                                this.loading = false;
                            }
                        })
                        .catch(() => {
                            console.log("删除失败");
                            this.loading = false;
                        });
                })
                .catch(() => {
                    this.$message("取消删除");
                });
    },
    },
};